﻿
/****************************** Module Header ******************************\

Copyright (c) Gary Davidson

This source is subject to the Microsoft Public License.
See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
All other rights reserved.

THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/

using System;
using System.Collections.Generic;
using System.Xml.Linq;

namespace Savviety.ServiceManager.API.Criteria
{
    public class AndExpression : Expression
    {
        readonly List<SimpleExpression> _orExpressions = new List<SimpleExpression>();
        private bool _hasOrCriteria;

        public AndExpression(ICollection<SimpleExpression> expressions)
        {
            Root = new XElement(NameSpace +"And");
            
            if (expressions.Count < 2)
                throw new ArgumentException("You must add at least two expressions");


            Expressions.AddRange(expressions);
        }
        public void AddOr(List<SimpleExpression> expressions)
        {
            _orExpressions.AddRange(expressions);
            _hasOrCriteria = true;
        }
        
        public override XElement ToXElement()
        {
            if(_hasOrCriteria)
            {
                // add or data here
            }
            foreach (var expression in Expressions)
            {
                Root.Add(expression.ToXElement());
            }
            return Root;
        }

    }

    
}